package cn.maven.utils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * 数据库工具类
 */
public class PropertiesUtil {
    private static Properties properties;

    /**
     * 加载配置文件
     *
     * @param fileName
     */
    private static void readProperties(String fileName) {
        try {
            properties = new Properties();
            InputStreamReader inputStreamReader = new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName), "UTF-8");
            properties.load(inputStreamReader);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 根据key读取对应的value值
     *
     * @param fileName
     * @param key
     * @return
     */
    public static String getValue(String fileName, String key) {
        readProperties(fileName);
        return properties.getProperty(key);
    }

}
